import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'
import HomeView from '../views/HomeView.vue'
import SearchView from '../views/SearchView.vue'
import DetailView from '../views/DetailView.vue'
import NotFoundView from '@/views/NotFoundView.vue'

const router = createRouter({
    // history: createWebHashHistory(),
    history:createWebHistory(),
    routes: [
        {
            // vue重定向
            path: '/',
            redirect: '/home' // 如果访问的是 localhost:5173/#/ => localhost:5173/#/home
        },
        {
            path: '/login',
            component: ()=>import('@/views/LoginView.vue') // 懒加载
            // 全部打包点进哪个页面，加载哪个页面
        }, {
            name:'home',
            path: "/home/:id?", // ?id表示可有可无
            component: ()=>import('@/views/HomeView.vue')
        },
        {
            path: '/search',
            component: ()=>import('@/views/SearchView.vue')
        },  {
            path: '/counter',
            component: () => import("@/views/CountView.vue")
        },
        {
            path: '/anothercounter',
            component: () => import("@/views/AnotherCounter.vue")
        },
        {
            path: '/detail/:name/:index',
            component: ()=>import('@/views/DetailView.vue')
        },{ path: '/:pathMatch(.*)*', component: NotFoundView }], //最后一个 // 对应鸿蒙的router_map.json
}) // 创建路由实例对象

export default router // 到处路由实例对象